import Vue from 'vue'
import App from './App.vue'
import ElementUI from 'element-ui';
import '@/assets/css/color.css'
import 'element-ui/lib/theme-chalk/index.css';
import router from '@/router'
import store from '@/store';
import axios from "axios";
import VueLazyload from 'vue-lazyload'
// import 'babel-polyfill';//解决IE浏览器ES6的问题
import VueCropper from 'vue-cropper'

const $cookies = require('vue-cookies')
Vue.use($cookies)


Vue.use(VueLazyload, {
  preLoad: 1.3,
  loading: require('@/assets/img/loading.gif'),//加载中图片，一定要有，不然会一直重复加载占位图
  error: require('@/assets/img/loading.gif'),  //加载失败图片
  attempt: 1
})


Vue.use(VueCropper);
Vue.use(ElementUI);
Vue.config.productionTip = false
Vue.prototype.$http = axios;



// 设置浏览器标题
Vue.directive('title', {
  inserted: function (el) {
    document.title = el.dataset.title
  }
})

//接收响应拦截器
axios.interceptors.response.use(res => {
      let code = res.data.code;
      let msg = res.data.msg;
      if (code !== 200) {
        //失败
        let errors = '未知错误';
        let message = msg;
        if (res.data.error) {
          errors = Object.values(res.data.error);
          message = msg + ',原因:' + errors
        }
        Vue.prototype.$notify({
          title: '错误',
          message: message,
          type: 'error',
          offset: 160,
        });
      }
      return res
    },
    err => {
      /*if (err && err.res) {
          switch (err.res.status) {
              case 400: err.message = '请求错误(400)'; break;
              case 401: this.$router.push('/login'); break;
              case 403: err.message = '拒绝访问(403)'; break;
              case 404: err.message = '请求出错(404)'; break;
              case 408: err.message = '请求超时(408)'; break;
              case 500: err.message = '服务器错误(500)'; break;
              case 501: err.message = '服务未实现(501)'; break;
              case 502: err.message = '网络错误(502)'; break;
              case 503: err.message = '服务不可用(503)'; break;
              case 504: err.message = '网络超时(504)'; break;
              case 505: err.message = 'HTTP版本不受支持(505)'; break;
              default: err.message = `连接出错(${err.response.status})!`;
          }
      } else {
          err.message = '连接服务器失败!'
      }
      message.error(err.message);*/
      return Promise.reject(err);
    });

new Vue({
  router,
  store,
  render: h => h(App),
}).$mount('#app')

